﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Lookstone.Data.SQLite;
using Lookstone.IO;

namespace Weber.CS3280.Inventory.Data
{
	/// <summary>
	/// A ConnectionContext common for all of the Inventory project
	/// </summary>
	public class InventoryConnectionContext : SQLiteConnectionContext
	{
		public InventoryConnectionContext(bool connect = true)
			: base(InventoryConnectionString, connect)
		{
		}

		/// <summary>
		/// Constructs a BudgetConnectionContext and optionally opens the connection
		/// </summary>
		/// <param name="connectString">Connection string that points to a connection aside from the default connection</param>
		/// <param name="connect">Specifies whether or not to open the connection</param>
		public InventoryConnectionContext(string connectString, bool connect = true)
			: base(connectString)
		{
			if (connect)
				Connect();
		}

		public static string InventoryConnectionString
		{
			get
			{
				if (s_inventoryConnectionString.Length > 0)
					return s_inventoryConnectionString;

				StringBuilder builder = new StringBuilder();

				s_inventoryConnectionString = ConfigurationManager.AppSettings["InventoryConnection"];
				return s_inventoryConnectionString;
			}
		}

		private static string s_inventoryConnectionString = "";
	}
}
